<?php
/*********************/
require_once ( get_template_directory() . '/inc/white-theme-options.php' );
require_once ( get_template_directory() . '/inc/white-widgets.php' );
require_once ( get_template_directory() . '/inc/shortcode.php' );
require_once ( get_template_directory() . '/inc/white-post-options.php' );
/*********************/
if ( ! function_exists('white_change_mce_buttons') ) {
function white_change_mce_buttons( $initArray ) {
$initArray['theme_advanced_blockformats'] = 'p,h2,h3,h4,h5,h6,address,pre,code,emotions';
$initArray['theme_advanced_buttons3'] = 'sub,sup,styleselect';
$initArray['theme_advanced_styles'] = 'Align left=alignleft , Align right=alignright, Align center=aligncenter';
return $initArray;
    }
}
add_filter('tiny_mce_before_init', 'white_change_mce_buttons');
/*********************/	
if ( ! function_exists('white_tdav_css') ) {
	function white_tdav_css($wp) {
		$wp .= ',' . get_stylesheet_directory_uri() . '/inc/css/tinymce.css';
		return $wp;
	}
}
add_filter( 'mce_css', 'white_tdav_css' );
/*********************/
function white_widgets_init() {
	register_sidebar( array(
		'name' => __( 'Sidebar Widget Area', 'mt-white' ),
		'id' => 'primary-widget-area',
		'description' => __( 'The primary widget area', 'mt-white' ),
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => __( 'Footer Widget Area', 'mt-white' ),
		'id' => 'footer-widget-area',
		'description' => __( 'The secondary widget area', 'mt-white' ),
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
}
add_action( 'widgets_init', 'white_widgets_init' );

/*********************/
if ( ! function_exists('white_pagination') ) {
	function white_pagination() {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;

$pagination = array(
	'base' => @add_query_arg('paged','%#%'),
	'format' => '',
	'total' => $wp_query->max_num_pages,
	'current' => $current,
	'show_all' => false,
    'mid_size' => 4,
    'end_size'     => 2,
	'type' => 'plain'
	);

if( $wp_rewrite->using_permalinks() )
	$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );

if( !empty($wp_query->query_vars['s']) )
	$pagination['add_args'] = array( 's' => get_query_var( 's' ) );

echo '<div class="wp-pagenavi">' .paginate_links($pagination).'</div>' ;
	}
}
/*********************/
add_action( 'after_setup_theme', 'white_setup' );

if ( ! function_exists( 'white_setup' ) ):
	function white_setup() {
/*********************/
load_theme_textdomain( 'mt-white', get_template_directory() . '/languages' );
/*********************/	
function white_print() {
	if ( ! is_admin() ){
	wp_register_style('print', get_template_directory_uri() .'/print.css', '', '1.0','print');
	wp_enqueue_style('print');	
	}   
}
add_action('wp_print_styles', 'white_print');
/*********************/
 function white_slide() {
 	if ( ! is_admin() ){
    wp_enqueue_script('jquery');
	wp_register_script('white-slide', get_template_directory_uri() .'/js/slides.min.jquery.js', array('jquery'));	   
}
}
add_action('init', 'white_slide');
/*********************/	
function white_new_excerpt_length($length) {
	return 80;
}
add_filter('excerpt_length', 'white_new_excerpt_length');
/*********************/	
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 610, 200, true );
add_image_size('single_post', 610, 200, true);
set_post_thumbnail_size( 620, 320, true );
add_image_size('slide', 620, 320, true);
add_theme_support( 'post-formats', array( 'aside', 'gallery','link') );
add_theme_support( 'automatic-feed-links' );
/*********************/	
add_editor_style();
/*********************/	
add_custom_background();
/*********************/
if ( ! isset( $content_width ) )
	$content_width = 620;
/*********************/
if (function_exists('wp_nav_menu')) {
register_nav_menus(array('primary' =>__( 'Primary Navigation', 'mt-white' )));
}
/*********************/
function white_recent_comments_style() {
	global $wp_widget_factory;
	remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
}
add_action( 'widgets_init', 'white_recent_comments_style' );
/*********************/
function white_menu_args( $args ) {
	$args['show_home'] = true;
	return $args;
}
add_filter( 'wp_page_menu_args', 'white_menu_args' );
/*********************/
add_filter('use_default_gallery_style', '__return_false');
/*********************/
add_custom_background();
	if ( ! defined( 'HEADER_IMAGE' ) )
		define( 'HEADER_IMAGE', '%s/images/header.jpg' );
/*********************/
	if ( ! defined( 'NO_HEADER_TEXT' ) )
		define( 'NO_HEADER_TEXT', true );
/*********************/
	define( 'HEADER_IMAGE_WIDTH', apply_filters( 'white_header_image_width', 960 ) );
	define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'white_header_image_height', 200 ) );
	set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
	define( 'NO_HEADER_TEXT', true );
	add_custom_image_header( 'white_header_style', 'white_header_style' );
	register_default_headers( array(
		'inkwell' => array(
			'url' => '%s/images/headers/inkwell.jpg',
			'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg',
			'description' => __( 'Inkwell', 'mt-white' )
		)
	) );
/*********************/
function white_header_style() {
		if (get_header_image()){
?>
<style type="text/css">#header .container_12{background: url(<?php header_image();?>) no-repeat 0 0;
    width: <?php echo HEADER_IMAGE_WIDTH;?>px;
    min-height: <?php echo HEADER_IMAGE_HEIGHT;?>px;
    _height: <?php echo HEADER_IMAGE_HEIGHT;?>px;}</style>
<?php
} else{ ?>
<style type="text/css">#header .container_12{background: url(<?php header_image();?>) no-repeat 0 0;
    width: <?php echo HEADER_IMAGE_WIDTH;?>px;
    min-height: 140px;
    _height: 140px;}
    #header h1, #header h2 {
    top:0;}</style>
<?php	
}
}
/*********************/	
	
/*********************/
if ( ! function_exists( 'white_posted_on' ) ) :
function white_posted_on() {
printf( __( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>, ' , 'mt-white' ),
get_permalink(), esc_attr( get_the_time() ), get_the_date()
);
}
endif;
/*********************/
}/****end setup***/
endif;
/*********************/
if ( ! function_exists( 'custom_comments' ) ) :
function custom_comments( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
	?>
	<li <?php comment_class();?> id="li-comment-<?php comment_ID();?>">
		<div id="comment-<?php comment_ID();?>">
		<div class="comment-author vcard">
			<?php echo get_avatar($comment, 40);?>
			<?php printf(__('%s <span class="says">says:</span>', 'mt-white'), sprintf('<cite class="fn">%s</cite>', get_comment_author_link()));?>
		</div><!-- .comment-author .vcard -->
		<?php if ( $comment->comment_approved == '0' ) : ?>
			<em><?php _e('Your comment is awaiting moderation.', 'mt-white');?></em>
			<br />
		<?php endif;?>

		<div class="comment-meta commentmetadata"><a href="<?php echo esc_url(get_comment_link($comment -> comment_ID));?>">
			<?php
			/* translators: 1: date, 2: time */
			printf(__('%1$s at %2$s', 'mt-white'), get_comment_date(), get_comment_time());
 ?></a><?php edit_comment_link(__('(Edit)', 'mt-white'), ' ');?>
		</div><!-- .comment-meta .commentmetadata -->

		<div class="comment-body"><?php comment_text();?></div>

		<div class="reply">
			<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'])));?>
		</div><!-- .reply -->
	</div><!-- #comment-##  -->

	<?php
	break;
	case 'pingback'  :
	case 'trackback' :
	?>
	<li class="post pingback">
		<p><?php _e('Pingback:', 'mt-white');?> <?php comment_author_link();?><?php edit_comment_link(__('(Edit)', 'mt-white'), ' ');?></p>
	<?php
	break;
	endswitch;
	}
	endif;
?>
